import Scanner from './Scanner.js';
import nestTokens from './nestTokens.js';
/**
 * 将模板字符串变为tokens数组
 */
export default function parseTemplateToTokens(templateStr) {
  var tokens = [];
  var scanner = new Scanner(templateStr);
  var words;
  while (!scanner.eos()) {
    words = scanner.scanUtil('{{');
    if (words != '') {
      tokens.push(['text', words]);
    }
    scanner.scan('{{');
    words = scanner.scanUtil('}}');
    if (words != '') {
      // 判断双大括号中间的东西是不是#开始
      if (words[0] == '#') {
        tokens.push(['#', words.substring(1)]);
      } else if (words[0] == '/') {
        tokens.push(['/', words.substring(1)]);
      } else {
        tokens.push(['name', words]);
      }
    }
    scanner.scan('}}');
  }
  return nestTokens(tokens);
}